<template>
    <div class="app-container">
        <el-form :label-position="labelPosition" label-width="80px" :model="formLabelAlign"  ref="formLabelAlign">
            <el-form-item label="医院介绍">
                <el-input v-model="formLabelAlign.introduce"   type="textarea" :autosize=true></el-input>
            </el-form-item>
            <el-form-item label="医院价值观">
                <el-input v-model="formLabelAlign.values" type="textarea"  :autosize=true></el-input>
            </el-form-item>
            <el-form-item label="咨询热线">
                <el-input v-model="formLabelAlign.bottom_tel"></el-input>
            </el-form-item>
            <el-form-item label="地址">
                <el-input v-model="formLabelAlign.bottom_address"></el-input>
            </el-form-item>
            <el-form-item label="接诊时间">
                <el-input v-model="formLabelAlign.bottom_time"></el-input>
            </el-form-item>
            <el-form-item label="二维码" prop="user_image">
                <el-upload
                        class="avatar-uploader"
                        :action="importFileUrl"
                        :show-file-list="false"
                        :on-success="handleAvatarSuccess"
                        :on-error="handleError"
                        :before-upload="beforeAvatarUpload"
                        :data="upLoadData"
                        :on-change="handleChange">
                    <img v-if="imageUrl" :src="imageUrl" class="avatar">
                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
            </el-form-item>
            <el-button style="text-align: right;" type="primary" @click="submit('formLabelAlign')">保存</el-button>
        </el-form>
    </div>
</template>
<style>
    .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }
    .avatar-uploader .el-upload:hover {
        border-color: #409EFF;
    }
    .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 178px;
        height: 178px;
        line-height: 178px;
        text-align: center;
    }
    .avatar {
        width: 178px;
        height: 178px;
        display: block;
    }
</style>
<script>
    export default {
        data() {
            return {
                activeNames: ['1'],
                imageUrl: '',
                importFileUrl: 'http://upload-z2.qiniup.com',
                labelPosition:'top',
                upLoadData: {token: '',},
                formLabelAlign: {
                    introduce: '',
                    values: '',
                    bottom_tel: '',
                    bottom_address: '',
                    bottom_time: '',
                    bottom_QR_code: '',
                }
            };
        },
        mounted() {
            this.getUptoken();
            this.getList();
        },
        methods: {
            handleChange(val) {

            },
            getList() {
                let _this = this;
                axios.get('/backend/brand').then(response => {
                    let { status, data, message } = response.data;
                    _this.formLabelAlign.bottom_QR_code = data.bottom.data[0].bottom_QR_code;
                    _this.formLabelAlign.bottom_address = data.bottom.data[0].bottom_address;
                    _this.formLabelAlign.bottom_tel = data.bottom.data[0].bottom_tel;
                    _this.formLabelAlign.bottom_time = data.bottom.data[0].bottom_time;
                    _this.formLabelAlign.introduce = data.copy.data[0].comment;
                    _this.formLabelAlign.values = data.copy.data[1].comment;
                    _this.imageUrl ='http://orrs4ojbz.bkt.clouddn.com/'+ data.bottom.data[0].bottom_QR_code;;
                })
            },
            submit(formName) {
                let _this = this;
                _this.$refs[formName].validate((valid) => {
                    if (valid) {
                        axios.post('/backend/brand/create', { 'data': _this.formLabelAlign }).then(response => {
                            let {status, data, message} = response.data;
                            if (!status) {
                                _this.$message.error(message);
                                return false;
                            }
                            _this.$message.success(message);
                            this.getList();
                        });
                    }
                });
            },
            getUptoken() {
                let _this = this;
                axios.get('api/qiniu/token').then(response => {
                    let { status, data, message } = response.data;
                    _this.upLoadData.token= data.uptoken;
                });
            },
            handleAvatarSuccess(res, file) {
                //上传成功后在图片框显示图片
                this.imageUrl ='http://orrs4ojbz.bkt.clouddn.com/'+ res.key;
                this.formLabelAlign.bottom_QR_code=res.key;
            },


        }
    }
</script>